package com.itheima.demo;

import java.util.Objects;

public class Person {
    private String name;
    private int age;

    public Person() {
    }



    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public String toString() {
        return "名字为"+name+"，年龄为"+age;
    }

       /*   @Override
  public boolean equals(Object obj) {
        Person p=(Person)obj;
        boolean b = this.name == name && this.age == age;
       return b;*/
       /*这里我使用equals重写的方法，并且由于多态的特性，我需要强强转

       */

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        //如果两个对象的地址值一样，所以直接返回true

        if (o == null || getClass() != o.getClass()) return false;
        //

        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name, age);
    }
}


